<template>
	<view class="container">
		<!-- 头部导航 -->
		<page-navbar title="交通状况" backgroundColor="#87CEEB00" color="#fff" leftIconColor="#fff"></page-navbar>
		<!-- 主要内容区域 -->
		<scroll-view class="content" scroll-y="true" :show-scrollbar="false">
			<!-- 搜索栏 -->
			<view class="search-section">
				<view class="search-box">
					<svg-icon name="search" size="20" class="search-icon" />
					<input class="search-input" placeholder="搜索景点、停车场" />
				</view>
			</view>
			<!-- 景点交通资讯 -->
			<view class="section">
				<view class="section-header">
					<svg-icon name="car" size="24" class="section-decoration" />
					<text class="section-title">景点交通资讯</text>
				</view>
				<view class="traffic-list" v-if="trafficList.length > 0">
					<view class="traffic-item" v-for="(item, index) in trafficList" :key="index"
						@click="handleParkingClick(item)">
						<view class="traffic-content">
							<view class="traffic-name">{{ item.name }}</view>
							<view class="traffic-desc">{{ item.introTitle }}</view>
						</view>
						<uni-icons type="right" color="#4CAF50" size="20"></uni-icons>
					</view>
				</view>
				<default-page v-else title="暂无景点信息" tip="景点信息正在准备中，敬请期待..."></default-page>
			</view>

			<!-- 附近停车场 -->
			<view class="section">
				<view class="section-header">
					<view class="section-decoration">🅿️</view>
					<text class="section-title">附近停车场</text>
				</view>
				<view class="parking-list" v-if="parkingList.length > 0">
					<view class="parking-item" v-for="(item, index) in parkingList" :key="index"
						@click="handleParkingClick(item)">
						<view class="parking-content">
							<view class="parking-name">{{ item.name }}</view>
							<view class="parking-info">
								<text class="parking-spaces">{{ item.introTitle }}</text>
							</view>
						</view>
						<view class="parking-action">
							<button class="guide-btn" @click.stop="navigateToParking(item)">导航</button>
						</view>
					</view>
				</view>
				<default-page v-else title="暂无停车场信息" tip="停车场信息正在准备中，敬请期待..."></default-page>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
import { ref, reactive, onMounted, watch, computed, nextTick, toRefs } from 'vue';
import { onLoad, onShow, onShareAppMessage } from '@dcloudio/uni-app';
import common from '@/utils/common.js';
import api from '@/api/index.js';

import useUserInfoStore from '@/stores/user';
import { storeToRefs } from 'pinia';
import SvgIcon from '@/components/svg-icon/svg-icon.vue'

const userInfoStore = useUserInfoStore();
const { userData } = toRefs(userInfoStore);

const imgUrl = uni.imgUrl;

// 景点交通资讯数据
const trafficList = ref([]);

// 停车场数据 - 使用成都地区的坐标
const parkingList = ref([]);

onLoad(() => { });

onMounted(() => {
	getList();
});

const getList = () => {
	api.attractionsApi.listSpots({ typeId: 12 }).then((res) => {
		console.log('停车场列表', res);
		parkingList.value = res
	})
	api.attractionsApi.listSpots({ typeId: 6 }).then((res) => {
		console.log('景点列表', res);
		trafficList.value = res
	})
};


// 点击目标地点
const handleParkingClick = (item) => {
	uni.showActionSheet({
		itemList: ['导航前往'],
		success: (res) => {
			switch (res.tapIndex) {
				case 0:
					if (item.position) {
						common.openMapNavigation(item.position.latitude, item.position.longitude, item.position.name);
					}
					break;
			}
		}
	});
};

</script>

<style lang="scss" scoped>
.container {
	background: linear-gradient(180deg, #87CEEB 0%, #F0F8FF 50%, #ffffff 100%);
	width: 100%;
	position: relative;
	overflow: hidden;
	box-sizing: border-box;
	display: flex;
	flex-direction: column;

	/* H5端适配 */
	/* #ifdef H5 */
	height: 100vh;
	min-height: 100vh;
	/* #endif */

	/* 小程序适配 */
	/* #ifdef MP */
	height: 100vh;
	/* #endif */

	/* App端适配 */
	/* #ifdef APP-PLUS */
	height: 100vh;
	/* #endif */
}

.content {
	flex: 1;
	overflow: hidden;
	box-sizing: border-box;
	position: relative;
	z-index: 1;
	padding: 0 30rpx;

	.search-section {
		padding: 0 30rpx 30rpx 30rpx;

		.search-box {
			display: flex;
			align-items: center;
			background: rgba(255, 255, 255, 0.9);
			border-radius: 50rpx;
			padding: 20rpx 30rpx;
			box-shadow: 0 4rpx 20rpx rgba(144, 238, 144, 0.15);

			.search-icon {
				font-size: 32rpx;
				margin-right: 20rpx;
				opacity: 0.6;
			}

			.search-input {
				flex: 1;
				font-size: 28rpx;
				color: #333;

				&::placeholder {
					color: #999;
				}
			}
		}
	}
}

.section {
	margin-bottom: 40rpx;

	.section-header {
		display: flex;
		align-items: center;
		margin-bottom: 20rpx;
		padding: 0 10rpx;
		gap: 20rpx;

		.section-title {
			font-size: 32rpx;
			font-weight: bold;
			color: #2E7D32;
		}

		.section-decoration {
			font-size: 28rpx;
			opacity: 0.7;
		}
	}
}

.traffic-list {
	.traffic-item {
		background: rgba(255, 255, 255, 0.95);
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-shadow: 4rpx 4rpx 20rpx rgba(144, 238, 144, 0.1);
		transition: all 0.3s ease;

		&:active {
			transform: scale(0.98);
			box-shadow: 0 2rpx 10rpx rgba(144, 238, 144, 0.2);
		}

		.traffic-content {
			flex: 1;

			.traffic-name {
				font-size: 30rpx;
				font-weight: bold;
				color: #2E7D32;
				margin-bottom: 10rpx;
			}

			.traffic-desc {
				font-size: 24rpx;
				color: #666;
				opacity: 0.8;
			}
		}
	}
}

.parking-list {
	.parking-item {
		background: rgba(255, 255, 255, 0.95);
		border-radius: 20rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		box-shadow: 4rpx 4rpx 20rpx rgba(144, 238, 144, 0.2);
		transition: all 0.3s ease;

		&:active {
			transform: scale(0.98);
		}

		.parking-content {
			flex: 1;

			.parking-name {
				font-size: 30rpx;
				font-weight: bold;
				color: #2E7D32;
				margin-bottom: 10rpx;
			}

			.parking-info {
				.parking-spaces {
					font-size: 24rpx;
					color: #4CAF50;
					font-weight: 500;
				}
			}
		}

		.parking-action {
			.guide-btn {
				background: linear-gradient(135deg, #4CAF50, #66BB6A);
				color: white;
				border: none;
				border-radius: 30rpx;
				padding: 15rpx 30rpx;
				font-size: 24rpx;
				font-weight: bold;
				box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.3);
				cursor: pointer;
				transition: all 0.3s ease;

				&::after {
					border: none;
				}

				&:active {
					transform: scale(0.95);
				}

				/* H5端鼠标悬停效果 */
				/* #ifdef H5 */
				&:hover {
					background: linear-gradient(135deg, #45a049, #5dae61);
					transform: translateY(-2rpx);
					box-shadow: 0 6rpx 16rpx rgba(76, 175, 80, 0.4);
				}

				/* #endif */
			}
		}
	}
}
</style>
